home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfbreak.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  1.6 KB  |  64 lines

  1. <!--- This example shows the use of CFBREAK to exit
  2. a loop when a condition is met --->
  3.  
  4. <!--- select a list of courses and use CFLOOP to find a condition
  5. and then break the loop --->
  6. <!--- check that number is numeric --->
  7. <CFIF IsDefined("form.number")>
  8.     <CFIF Not IsNumeric(form.number)>
  9.         <CFABORT>
  10.     </CFIF>
  11. </CFIF>
  12.  
  13. <CFQUERY NAME="GetCourses" DATASOURCE="cfsnippets">
  14. SELECT * 
  15. FROM Courses
  16. ORDER by Course_Num
  17. </CFQUERY>
  18.  
  19. <HTML>
  20. <HEAD>
  21. <TITLE>
  22. CFBREAK Example
  23. </TITLE>
  24. </HEAD>
  25.  
  26. <BODY bgcolor=silver>
  27. <H3>CFBREAK Example</H3>
  28.  
  29. <P>This example uses CFLOOP to cycle through a query to find a desired value.
  30. (In our example, a list of values corresponding to courses in the Snippets datasource).
  31. When the conditions of the query are met, CFBREAK stops the loop.
  32.  
  33. <P>Please enter a Course Number, and hit the "submit" button:
  34.  
  35. <FORM ACTION="cfbreak.cfm" METHOD="POST">
  36. <SELECT NAME="courseNum">
  37. <CFOUTPUT query="GetCourses">
  38. <OPTION VALUE="#Course_Num#">#Course_Num#
  39. </CFOUTPUT>
  40. </SELECT>
  41. <INPUT TYPE="Submit" NAME="" VALUE="Search on my Number">
  42. </FORM>
  43.  
  44. <!--- if the courseNum variable is not defined, don't loop
  45. through the query --->
  46. <CFIF IsDefined ("form.courseNum") is "True">
  47.  
  48. <!--- loop through the query until desired value is found,
  49. then use CFBREAK to exit the query --->
  50. <CFLOOP QUERY="GetCourses">
  51.     <CFIF GetCourses.Course_Num is form.courseNum>
  52.     <CFOUTPUT>
  53.     <H4>Your Desired Course was found:</H4>
  54.     <PRE>#Course_Num#    #Descript#</PRE></CFOUTPUT>
  55.     <CFBREAK>
  56.     <CFELSE>
  57.         <BR>Searching... 
  58.     </CFIF>
  59. </CFLOOP>
  60. </CFIF>
  61.  
  62. </BODY>
  63. </HTML>       
  64.